package com.gssuren.demo.collector;

import com.gssuren.demo.model.User;
import com.gssuren.demo.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "api/user")
public class UserRestController {
    @Resource
    private UserService userService;


    @RequestMapping(method = RequestMethod.POST)
    public boolean addUser(@RequestBody User user) {
        System.out.println("开始新增");
        return userService.addUser(user);
    }

    @RequestMapping(method = RequestMethod.PUT)
    public boolean updateUser(@RequestBody User user) {
        System.out.println("开始修改");
        return userService.updateUser(user);
    }

    @RequestMapping(method = RequestMethod.DELETE)
    public boolean delteUser(@RequestParam(value = "userId", required = true) int userId) {
        System.out.println("开始删除");
        return userService.deleteUser(userId);
    }

    @RequestMapping(method = RequestMethod.GET)
    public List<User> findUserByName(@RequestParam(value = "userName", required = true) String userName) {
        System.out.println("开始查找");
        return userService.findUserByName(userName);
    }
}